// 动态规划
var maxProfit = function (prices) {
  let profit = 0,
      min = price[0];
  for (let i = 1; i < prices.length; i++) {
    min = Math.min(min, prices[i]);
    profit = Math.max(profit, prices[i] - min);
  }
  return profit;
}